/*
* 定义在[1, 1000000] 这个区间中的性质如下
* 对于区间中的某一个点x
* 求出从1走到N, 最少经过的长度大于x的边的数量是否小于等于k

* 将边分类，如果边长大于x, 则边权看成1, 否则边权是0
* 用双端队列BFS来求从1到N的最短路
* 性质结果就是 y <= k
*/
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
// #define ONLINE_GUDGE
using namespace std;
using PII = pair<int, int>;
const int N = 1010, M = 20010, INF = 0x3f3f3f3f;

int n, m, k;
int h[N], e[M], w[M], ne[M], idx;
deque<int> q;
int dist[N];
bool st[N];

void AddEdge(int a, int b, int c)
{
    e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx ++ ;
}

bool check(int bound) // 边权下限
{
    memset(st, 0, sizeof st);
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    q.push_back(1);

    while(q.size())
    {
        int u = q.front();
        q.pop_front();

        if(st[u]) continue;
        st[u] = 1;

        for(int i = h[u]; ~i; i = ne[i])
        {
            int v = e[i], judge = w[i] > bound;
            if(dist[v] > dist[u] + judge)
            {
                dist[v] = dist[u] + judge;
                if(!judge) q.push_front(v);
                else q.push_back(v);
            }
        }
    }
    return dist[n] <= k;
}

int main()
{
    #ifdef ONLINE_JUDGE

    #else
        freopen("./in.txt", "r", stdin);
    #endif

    ios::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m >> k;

    memset(h, -1, sizeof h);

    while(m--)
    {
        int a, b, c; cin >> a >> b >> c;
        AddEdge(a, b, c); AddEdge(b, a, c);
    }

    int l = 0, r = 1e6+1;
    while(l < r) // 二分枚举权值 求得满足条件的边权下限最高值
    {
        int mid = (l + r) >> 1;
        if(check(mid)) r = mid; // 
        else l = mid+1;
    }

    if(r == 1e6+1) r = -1;
    cout << r << endl;

    return 0;
}